// 引入 axios
import axios from "axios";
import METHOD from "./methods";
// import index from "./index"


const BASEURL = "https://api.it120.cc/small4";
// 创建axios配置实例

const axiosInstance = axios.create({
    baseURL: BASEURL,//默认会拼接到请求路径前面
    tiemout: 10000
});

// 在请求之前 弹出loading组件
// 添加请求拦截器
axiosInstance.interceptors.request.use(function (config) {
    
    return config;
}, function (error) {
    return Promise.reject(error)
});

// 请求结束后 收起loading组件
axiosInstance.interceptors.response.use(function (response) {
    return response
}, function (error) {
    return Promise.reject(error)
})

export function request(method, url, params) {
    switch (method) {
        case METHOD.GET:
            return GET(url, params);
        case METHOD.POST:
            return POST(url, params)
    }
}

// 请求方式
function GET(url, params) {
    return axiosInstance.get(url, params);
}
function POST(url, params) {
    return axiosInstance.post(url, params)
}